﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 护士工作站
{
    public partial class 取消转出 : Form
    {
        public 取消转出()
        {
            InitializeComponent();
        }

        private void button_qp_Click(object sender, EventArgs e)
        {

            tb_bqzt.Text = "";
            tb_ch.Text = "";
            tb_ssks.Text = "";
            tb_nl.Text = "";
            tb_ryrq.Text = "";

            tb_xb.Text = "";
            tb_xm.Text = "";
            tb_yjje.Text = "";
            tb_ys.Text = "";
            tb_fyhj.Text = "";

            tb_ZYNo.Text = "";
            tb_hldj.Text = "";
           
        }

        private void button_tc_Click(object sender, EventArgs e)
        {
            this.Hide();
           
        }

        private void button_bc_Click(object sender, EventArgs e)
        {
            string bedNo = tb_ch.Text.Trim();
            string hosNo = tb_ZYNo.Text.Trim();
           
            using (SqlConnection conn = new SqlConnection(DBHelper.connString))
            {


                string str = string.Format("insert into  InHospital( HosNo, BedNo, HosIndate, HosDepartment, HosPrepay, PatType, HosSurgerydate, HosRank, HosCondition, HosIllness,HosTotal,HosBalance,DocNo,NurNo,HosOfficeDate,HosArea)select HosNo, BedNo, HosIndate, HosDepartment, HosPrepay, PatType, HosSurgerydate, HosRank, HosCondition, HosIllness,HosTotal,HosBalance,DocNo,NurNo,HosOfficeDate,HosArea from TurnInWard2 where TurnInWard2.HosNo='" + hosNo + "'");
                string sql = string.Format("delete from TurnInWard1  where TurnInWard1.HosNo='" + hosNo + "'");
                string str1 = string.Format("delete from TurnInWard2  where TurnInWard2.HosNo='" + hosNo + "'");
                string ssql = string.Format("update Bed set BedCondition='已用'where Bed.BedNo='" + bedNo + "'");
                string sql1 = string.Format("update Patient set Condition='住院'where Patient.HosNo='" + hosNo + "'");
                SqlCommand com = new SqlCommand(str, conn);
                SqlCommand bed = new SqlCommand(ssql, conn);
                SqlCommand ins = new SqlCommand(sql, conn);
                SqlCommand dein = new SqlCommand(str1, conn);
                SqlCommand pat = new SqlCommand(sql1, conn);
                conn.Open();
                int m = Convert.ToInt32(com.ExecuteNonQuery());
                int n = Convert.ToInt32(dein.ExecuteNonQuery());
                int z = Convert.ToInt32(bed.ExecuteNonQuery());
                int y = Convert.ToInt32(ins.ExecuteNonQuery());
                int a = Convert.ToInt32(pat.ExecuteNonQuery());

                if (y == 1 && n == 1 && z == 1 && m == 1 && a == 1)
                {
                    MessageBox.Show("取消转出成功！");
                }
                else
                {
                    MessageBox.Show("取消转出失败！");
                }
            }

        }
           

        private void button_cx_Click(object sender, EventArgs e)
        {
            string ZYNo = tb_ZYNo.Text.Trim();
            string ch = tb_ch.Text.Trim();

            if (ZYNo == "" && ch == "")
            {
                MessageBox.Show("请输入要查询的内容！");
                tb_ZYNo.Focus();
                tb_ch.Focus();

                return;
            }


            string Hos = "select * from  TurnInWard2,Patient   where TurnInWard2.HosNo='" + ZYNo + "'and TurnInWard2.HosNo=Patient.HosNo";
            string Bed = "select * from TurnInWard2,Patient where BedNo='" + ch + "'and TurnInWard2.HosNo=Patient.HosNo";
            using (SqlConnection conn = new SqlConnection(DBHelper.connString))
            {

                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                SqlCommand cmd = new SqlCommand(Hos, conn);
                SqlCommand str = new SqlCommand(Bed, conn);

                if (ZYNo != "")
                {
                    SqlDataReader dr = cmd.ExecuteReader();

                    if (dr.HasRows)
                    {
                        dr.Read();

                        tb_fyhj.Text = dr["HosTotal"].ToString();

                        int nf = Convert.ToInt32(dr["BronYear"].ToString());
                        DateTime time = System.DateTime.Now;
                        int year = time.Year;
                        int nl = year - nf;
                        tb_nl.Text = nl.ToString();
                        tb_ryrq.Text = dr["HosIndate"].ToString();


                        tb_xb.Text = dr["PatSex"].ToString();
                        tb_xm.Text = dr["PatName"].ToString();
                        tb_ch.Text = dr["BedNo"].ToString();
                        tb_ssks.Text = dr["HosDepartment"].ToString();

                        tb_yjje.Text = dr["HosPrepay"].ToString();

                        tb_ZYNo.Text = dr["HosNo"].ToString();
                        tb_hldj.Text = dr["HosRank"].ToString();

                        string dno = dr["DocNo"].ToString();

                        dr.Close();

                        string DNo = "select DocName from Doctor where  DocNo='" + dno + "' ";
                        SqlCommand D = new SqlCommand(DNo, conn);

                        string DD = Convert.ToString(D.ExecuteScalar());

                        tb_ys.Text = DD;

                    }
                    dr.Close();
                }

                if (ch != "")
                {
                    SqlDataReader ds = str.ExecuteReader();
                    if (ds.HasRows)
                    {
                        ds.Read();

                        tb_fyhj.Text = ds["HosTotal"].ToString();

                        int nf = Convert.ToInt32(ds["BronYear"].ToString());
                        DateTime time = System.DateTime.Now;
                        int year = time.Year;
                        int nl = year - nf;
                        tb_nl.Text = nf.ToString();
                        tb_ryrq.Text = ds["HosIndate"].ToString();


                        tb_xb.Text = ds["PatSex"].ToString();
                        tb_xm.Text = ds["PatName"].ToString();
                        tb_ch.Text = ds["BedNo"].ToString();
                        tb_ssks.Text = ds["HosDepartment"].ToString();

                        tb_yjje.Text = ds["HosPrepay"].ToString();

                        tb_ZYNo.Text = ds["HosNo"].ToString();
                        tb_hldj.Text = ds["HosRank"].ToString();

                        string dno = ds["DocNo"].ToString();

                        ds.Close();

                        string DNo = "select DocName from Doctor where  DocNo='" + dno + "' ";
                        SqlCommand D = new SqlCommand(DNo, conn);

                        string DD = Convert.ToString(D.ExecuteScalar());

                        tb_ys.Text = DD;

                    }
                    ds.Close();
                }

            }
        }
        }

      

       

      

    
    }

